package com.atguigu.rabbit.producer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Worker Hu
 * @CreateTime: 2024-07-23  16:33
 */
@Configuration
public class RabbitConfig {

    // 声明交换机
    @Bean
    public Exchange fanoutExchange() {
        Exchange fanoutExchange = ExchangeBuilder.fanoutExchange("pubsub_exchange01").durable(true).build();
        return fanoutExchange ;
    }

    // 声明队列
    @Bean
    public Queue fanoutQueue01() {
        Queue queue = QueueBuilder.durable("pubsub_queue01").build();
        return queue ;
    }

    // 声明队列
    @Bean
    public Queue fanoutQueue02() {
        Queue queue = QueueBuilder.durable("pubsub_queue02").build();
        return queue ;
    }

    // 声明队列和交换机的绑定信息
    @Bean
    public Binding fanoutQueue01Binding() {
        Binding binding = BindingBuilder.bind(fanoutQueue01())
                .to(fanoutExchange())
                .with("").noargs();
        return binding ;
    }

    @Bean
    public Binding fanoutQueue02Binding() {
        Binding binding = BindingBuilder.bind(fanoutQueue02()).to(fanoutExchange()).with("").noargs();
        return binding ;
    }

}

